import { createApp } from 'vue';
import App from './App.vue';
import router from './router';  // 引入路由配置
import ElementPlus from 'element-plus';
import  'element-plus/dist/index.css' 
//axios 
import axios from 'axios'
//echarts
import ECharts from 'vue-echarts'
import "echarts"
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

import WordCloud from 'wordcloud';  

function parseLyrics(lyricsText) {
  var lyrics = [];
  var lines = lyricsText.split('\n');
  for (var i = 0; i < lines.length; i++) {
    if (lines[i].indexOf('[') === -1) continue; // 检查是否有时间戳
    var parts = lines[i].split(']');
    var timePart = parts[0].substring(1).trim(); // 获取时间戳部分并去除多余空白
    var timeMatches = timePart.match(/(\d+):(\d+)/); // 匹配分钟和秒
    if (!timeMatches) continue; // 如果没有匹配到时间戳，跳过当前行

    var minutes = parseInt(timeMatches[1], 10); // 分钟
    var seconds = parseInt(timeMatches[2], 10); // 秒

    var timeInSeconds = minutes * 60 + seconds; // 转换为秒
    lyrics.push({
      time: timeInSeconds,
      text: parts[1].trim()
    });
  }
  return lyrics;
}


const app = createApp(App)
app.use(router).component('e-charts',ECharts).use(ElementPlus).mount('#app')
axios.defaults.baseURL="http://localhost:8080"
app.config.globalProperties.$http= axios
app.config.globalProperties.$parseLyrics = parseLyrics // 将 parseLyrics 添加到全局属性
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
  }

 
  // 将词云库添加到全局属性
app.config.globalProperties.$wordCloud = WordCloud;


